//重置样式
require('../../assets/css/index.less')

//引入weui库
require('../../assets/lib/weui/weui.css')
let weui = require('../../assets/lib/weui/weui.js')
console.log(weui);

//当前页面样式
require('./circle.less')

//引入字体库
require('../../assets/fonts/iconfont.css')

//引入dom
const dom = require('../../utils/dom.js')

//引入https
const https = require('../../utils/https.js')




dom.reday(function () {

    dom.footerH('circle')

    //点击跳转发布动态
    dom.getEvent('#localDynamic', function () {
        location.href = 'dynamic.html'
    })

    //获取数据
    function getData() {
        https.get('/api/train/courseList', function (res) {
            console.log(res);
            let { errno, data } = res
            if (errno == 0) {
                setData(dom.getEle('#newCourse'), data)
            }
        })
    }
    getData()

    //渲染数据
    function setData(node, data) {
        node.innerHTML += `
        <div>
        <img src="${https.BASE_URL + data[0].imgurl}" alt="" data-id="${data[0].courseId}">
        </div>
        <h2>${data[0].name}</h2>
        <p class="font14">${data[0].desc}</p>
        `
    }

    //点击跳转课程训练 并传值过去
    // dom.getEvent('#localInt', function () {
    //     location.href = 'introduce.html'
    // })

    dom.getEle('#newCourse').addEventListener('click',function(event){
        if(event.target.nodeName=='IMG'){
            let id = event.target.dataset['id']
            console.log(id);
            location.href = `introduce.html?id=`+id
        }
        
    })
})